{extend name="base"/}
{block name="content"}
<div id="header-frame">
    {include file="public:top" /}
    <script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery-2.0.3.min.js'></script>
    <script type='text/javascript' src='__STATIC__/admin/uploadajax/js/jquery.form.js'></script>
    <link href="__STATIC__/admin/uploadajax/css/style.css" type="text/css" rel="stylesheet"/>
</div>
<div id="frame-body">
    <div id="menu-frame" style="width: 100%;float: left;">
        {include file="public:menu" /}


    </div>
    <div id="main-frame" style="float: left;">
        <div id="dcMain" style="margin-left: 20px;width: 1682px;">
            <div id="urHere">DouPHP 管理中心<b>></b><strong>商品分类</strong> </div>   <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
            <h3><a href="{:url('admin/product/specific')}?pid={$productsData.products_id}" class="actionBtn add">添加规格</a>商品分类</h3>
            <style>
                .tableBasic tr th,td{
                    height: 40px;
                }
                .tableBasic tr .buttonOn a{
                    margin: 0 auto;
                    display:inline-block;
                    padding: 0 10px;
                    height: 24px;
                    line-height: 24px;
                    font-size: 12px;
                    color: #ffffff;
                    background: #009E94;
                    border-radius: 10px;
                }
                .tableBasic tr .buttonOn a{
                    margin: 0 auto;
                    display:inline-block;
                    padding: 0 10px;
                    height: 24px;
                    line-height: 24px;
                    font-size: 12px;
                    color: #ffffff;
                    background: #009E94;
                    border-radius: 10px;
                }
                .th{

                }
            </style>
            <form id='myupload' action="" method='post' >
                <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
                    <tr>
                        <th colspan="{$SpecifcData['res']['count']}" align="center">规格元素</th>
                        <th rowspan="2" align="center">价格</th>
                        <th rowspan="2" align="center">库存</th>
                        <th rowspan="2" align="center">图片</th>
                        <th rowspan="2" align="center">操作</th>
                    </tr>
                    <tr>
                        {foreach name="SpecifcData.res.comm" item="vo"}
                        <td align="center">{$vo.pspecifications_type}</td>
                        {/foreach}
                    </tr>
                    {foreach name="SpecifcData.data" item="vo"}

                    <tr>
                        <?php
                  for($i=0;$i<count($vo['pspeci_element']);$i++)
                  {
                  echo '<td align="center" >'.$vo['pspeci_element'][$i].'</td>';
                        }
                        ?>
                        <td align="center"><input type="text" name="pspeci_price[]" value="{$vo['pspeci_price']}" >单位:元  <a  onclick="editPrice(this,{$vo['pspeci_id']})">修改</a></td>
                        <td align="center"><input type="text" name="pspeci_stock[]" value="{$vo['pspeci_stock']}">单位:件  <a  onclick="editStock(this,{$vo['pspeci_id']})">修改</a></td>
                        <td align="center"><img src="{$vo['pspeci_img']}"/></td>
                        <td align="center" class="buttonOn"><a onclick="delSpecification(this,{$vo['pspeci_id']})">删除</a> | <a onclick="shelf(this,{$vo['pspeci_id']})">{$vo['pspeci_states']? '下架':'上架'}</a></td>

                    </tr>
                    {/foreach}
                </table>
                <input type="hidden" name="products_id"  value='{$productsData.products_id}'/>
            </form>
        </div>
        </div>
        <div class="clear"></div>
        <script type="text/javascript">
            function editPrice(txt,id)
            {
                var value=$(txt).prev("input").val();
                var url="{:url('admin/product/editSpr')}";
                var data={id:id,value:value};
                $.post(url,data,function(result){

                    if(result.status=='4')
                    {
                        dialog.error(result.message);
                    }else
                    {
                        dialog.error(result.message);
                    }
                })
            }
            function editStock(txt,id)
            {
                var value=$(txt).prev("input").val();
                var url="{:url('admin/product/editStock')}";
                var data={id:id,value:value};
                $.post(url,data,function(result){

                    if(result.status=='4')
                    {
                        dialog.error(result.message);
                    }else
                    {
                        dialog.error(result.message);
                    }
                })
            }

            function specific_add(that){
                var  products_id={$productsData.products_id};
                var success_url="{:url('admin/product/index')}?pid="+products_id;
                var url="{:url('admin/product/product_specific')}";
                var admins=$("#myupload").serialize();
                $.post(url,admins,function(result){

                    if(result.status=='4')
                    {
                        dialog.success(result.message,success_url);
                    }else
                    {
                        dialog.error(result.message);
                    }
                })
            }
            function delSpecification(that,id){
                var url="{:url('admin/product/deleteInfo')}";
                var data={id:id};
                $.post(url,data,function(result){

                    if(result.status=='4')
                    {
                        $(that).parents("tr").remove();
                        dialog.error(result.message);
                    }else
                    {
                        dialog.error(result.message);
                    }
                })

            }
            function shelf(that,id){
                var  products_id={$productsData.products_id};
                var url="{:url('admin/product/shelf')}";
                var success_url="{:url('admin/product/product_specificindex')}?pid="+products_id;
                var data={id:id};
                $.post(url,data,function(result){

                    if(result.status=='4')
                    {
                        dialog.success(result.message,success_url);
                    }else
                    {
                        dialog.error(result.message);
                    }
                })

            }
        </script>
        {/block}